home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3.adf / Exec / piarc.LZH / pcxload.rexx < prev    next >
OS/2 REXX Batch file  |  1992-07-30  |  6KB  |  197 lines

  1. /*
  2.  * PCXload.rexx       Load Z Soft / PC Paintbrush  PCX files
  3.  *
  4.  *  Written by: Barry Chalmers
  5.  * Last Update: July 31st, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.00 -  Initial version  1,4, and 8 bit files
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate script without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41.   cmdpath = 'c:';
  42.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  43.     do
  44.       cmdpath = readln(fhandle);
  45.       call close(fhandle);  /* close the file    */
  46.     end
  47.  
  48. prevpath = 'ram:'; /* put user in ram to start with... */
  49. if show('C',rgbpath) = 1 then do
  50.   prevpath = getclip(rgbpath);
  51.   end;
  52. prevname = '';
  53. if show('C',rgbname) = 1 then do
  54.   prevname = getclip(rgbname);
  55.   end;
  56.  
  57. address(prtnme);
  58.  'autoredraw 0';
  59.  
  60.   options results;
  61.   'filerequest "'||prevpath||'","'||prevname||'",".pcx","Load PCX"';
  62.   rgbfile = result;
  63.   options;
  64.   if rgbfile = 'FR_CANCELLED' then do
  65.     address(prtnme);
  66.     'tofront';
  67.     exit 0;
  68.     end;
  69.   rgbfile = expandfilename(rgbfile);
  70.   prevpath = gimmepath(rgbfile);
  71.   call setclip(rgbpath,prevpath);
  72.   prevname = gimmename(rgbfile);
  73.   call setclip(rgbname,prevname);
  74.   prevext = gimmeext(rgbfile);
  75.   
  76. address command 'cmpi:PCXload report '||rgbfile;
  77.  
  78. if open(fhandle,'ram:PCX.report','read') then  /* open the file */
  79.   do
  80.     xw = readln(fhandle);
  81.     yw = readln(fhandle);
  82.     call close(fhandle);  /* close the file    */
  83.   end
  84.  
  85. 'newasprimary '||xw||','||yw||','||prevname;
  86.  
  87. address(prtnme);
  88. options results;
  89. 'jackin';
  90. jack = result;
  91. options;
  92. address command 'cmpi:PCXload load '||jack||' '||rgbfile;
  93.  
  94. address(prtnme);
  95. 'autoredraw 1';
  96. 'redraw';
  97.  
  98. exit 0;  /* The end   */
  99.  
  100.  
  101.  
  102. /*
  103.  * gimmepath
  104.  *
  105.  * This takes the provided argument and sucks the path out of it, then
  106.  * returns that path to the caller, sans file name.
  107.  */
  108. gimmepath:
  109.   arg fullnamegx;
  110.     tempgx = reverse(fullnamegx);
  111.     lengx = length(fullnamegx);   /* get length of string */
  112.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  113.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  114.     seploc = 0; /* assumes current dir, no path supplied */
  115.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  116.       seploc = (lengx - slashdex)+1;
  117.       end;
  118.     else do
  119.       if colondex ~= 0 then do /* we assume we are on a device */
  120.         seploc = (lengx - colondex)+1;
  121.         end;
  122.       end;
  123.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  124.   gxpath = left(fullnamegx,seploc);
  125.   return(gxpath);
  126.  
  127. /*
  128.  * Since this script can't be expected to know where the CD of the user
  129.  * is when this cmd is invoked, we have to check the path the user
  130.  * provides - if it's not specified right from a root, then we have
  131.  * to make it a complete specification from the root.
  132.  */
  133. expandfilename:
  134.   parse arg jfile;
  135.   if index(jfile,':') = 0 then do
  136.     curdir = pragma(D);
  137.     if right(curdir,1) ~= ':' then do
  138.       if right(curdir,1) ~= '/' then do
  139.         if curdir ~= '' then do
  140.           curdir = curdir || '/';
  141.           end;
  142.         end;
  143.       end;
  144.     jfile = curdir||jfile;
  145.     end;
  146.   return(jfile);
  147.  
  148. gimmename:
  149.   arg fullnamegx;
  150.     tempgx = reverse(fullnamegx);
  151.     lengx = length(fullnamegx);   /* get length of string */
  152.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  153.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  154.     seploc = 0; /* assumes current dir, no path supplied */
  155.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  156.       seploc = (lengx - slashdex)+1;
  157.       end;
  158.     else do
  159.       if colondex ~= 0 then do /* we assume we are on a device */
  160.         seploc = (lengx - colondex)+1;
  161.         end;
  162.       end;
  163.   extpos = lastpos(".",fullnamegx) - 2;
  164.   if extpos > seploc then do
  165.     gxname = substr(fullnamegx,seploc+1,extpos-seploc+1);
  166.     end;
  167.   else do
  168.     gxname = substr(fullnamegx,seploc+1);
  169.     end;
  170.   return(gxname);
  171.   end
  172.  
  173. gimmeext:
  174.   arg fullnamegx;
  175.     tempgx = reverse(fullnamegx);
  176.     lengx = length(fullnamegx);   /* get length of string */
  177.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  178.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  179.     seploc = 0; /* assumes current dir, no path supplied */
  180.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  181.       seploc = (lengx - slashdex)+1;
  182.       end;
  183.     else do
  184.       if colondex ~= 0 then do /* we assume we are on a device */
  185.         seploc = (lengx - colondex)+1;
  186.         end;
  187.       end;
  188.   extpos = lastpos(".",fullnamegx) - 2;
  189.   if extpos > seploc then do
  190.     gxext = substr(fullnamegx,extpos+2);
  191.     end;
  192.   else do
  193.     gxext = '';
  194.     end;
  195.   return(gxext);
  196.   end
  197.